//
//  ZStatusRetweetView.swift
//  swift-weibo
//
//  Created by zero on 17/3/25.
//  Copyright © 2017年 zero. All rights reserved.
//

import UIKit

import SnapKit

class ZStatusRetweetView: UIView {

    // 记录转发微博底部约束
    var retweetViewBottomConstraint: Constraint?
    
    var homeModelViewModel:ZHomeModelViewModel?{
        
        didSet{
            
            labContent.attributedText = homeModelViewModel?.retweetContentString
            
            //  移除约束
            retweetViewBottomConstraint?.deactivate()
            
            if let picUrls = homeModelViewModel?.homeModel?.retweeted_status?.pic_urls,picUrls.count > 0{
                
                pictureView.picUrls = picUrls
                
                //  设置约束
                
                self.snp.makeConstraints({ (make) in
                    
                    retweetViewBottomConstraint = make.bottom.equalTo(pictureView.snp.bottom).offset(8).constraint
                })
                
                pictureView.isHidden = false
            }else{
                
                self.snp.makeConstraints({ (make) in
                    
                    retweetViewBottomConstraint = make.bottom.equalTo(labContent.snp.bottom).offset(8).constraint
                })
                
                pictureView.isHidden = true
            }

        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        //  布局
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
 
    
    //  布局
    private func setupUI(){
        
        addSubview(labContent)
        
        labContent.numberOfLines = 0
        labContent.preferredMaxLayoutWidth = 355
        //  约束
        labContent.snp.makeConstraints { (make) in
            
            make.leading.equalTo(self).offset(8)
            make.top.equalTo(self)
            
        }
        addSubview(pictureView)
        
        pictureView.backgroundColor = UIColor.lightGray
        //  添加图片
        pictureView.snp.makeConstraints { (make) in
            
            make.left.equalTo(8)
            make.top.equalTo(labContent.snp.bottom).offset(8)
        }
        
        self.snp.makeConstraints { (make) in
            
            retweetViewBottomConstraint = make.bottom.equalTo(pictureView).offset(8).constraint
        }
        

    }
    
    //  内容
    
    private var labContent = UILabel(title: "转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博", fontColor: UIColor.black, fontSize: 14)
    
    private lazy var pictureView:ZStatusPictureView = ZStatusPictureView()
}
